/*
 * Copyright (C) 2008 Peter Kling
 *
 * This file is part of 'A Kind of Billiard', a graphical billiard simulation.
 *
 * 'A Kind of Billiard' is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * 'A Kind of Billiard' is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * 'A Kind of Billiard'. If not, see <http://www.gnu.org/licenses/>.
 */

package cg2.mathematics;

/**
 * @brief A plane in the (three dimensional) euclidean space.
 * 
 * Internally the plane is stored in "Hesse-Normalenform".
 */
public class MathPlane {
	private MathVector normal;
	private double     d;
	
	/**
	 * @brief Creates a plane with the given normal and distance.
	 * 
	 * The parameters normal and d need not to be given in "Hesse-Normalenform" but rather as an arbitrary (not
	 * necessarily normalized) normal pointing from the origin towards the plane and the distance of the plane to the
	 * origin. The internally stored normal will be normalized.
	 * 
	 * @throws IllegalArgumentException If d is negative or the normal has length 0.
	 */
	public MathPlane(MathVector normal, double d) {
		if (normal.dim != 3)
			throw new IllegalArgumentException("Normal vector of plane must have dimension 3.");
		if (d < 0 || normal.norm() == 0)
			throw new IllegalArgumentException("Got malformed normal vector or distance for plane.");
		
		this.normal = normal.clone();
		this.d      = d;
		this.normal.normalize();
	}
	
	/**
	 * @brief Returns the distance between the origin and this plane.
	 */
	public double getDistance() {
		return d;
	}
	
	/**
	 * @brief Returns a vector representing the normalized normal of this plane (pointing from the origin to the plane).
	 */
	public MathVector getNormal() {
		return normal.clone();
	}
}
